from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 反向用例 ： case_005  旧密码错误，修改失败

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://beijing.anjuke.com/')
# 强制等待
sleep(2)
# 隐式等待
driver.implicitly_wait(10)
# 点击登录
driver.find_element(By.CSS_SELECTOR, '.user-login').click()
sleep(30)
# 悬停在“PXYRtET”上
try:
    xt = driver.find_element(By.XPATH,
                             '/html/body/div[1]/div/div/div[1]/div[1]/div[6]/div[2]/div/div/div[4]/div/div/p/span')
    ActionChains(driver).move_to_element(xt).perform()
except Exception as e:
    print(f'异常：{e}')
    raise
sleep(3)
# 显示等待   点击我的消息
xx = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, '我的消息'))
)
xx.click()
sleep(2)
# 点击个人资料
driver.find_element(By.XPATH, '/html/body/div[3]/div/div[1]/ul/li[5]/a').click()
sleep(2)
# 点击密码后的修改按钮
driver.find_element(By.CSS_SELECTOR, 'body > div.container > div > div.right-content > div.right-cont > div.profile > ul:nth-child(2) > li.password > a').click()
sleep(2)
# 输入旧密码
driver.find_element(By.XPATH, '/html/body/div[3]/div/div[2]/div[1]/div/form/div[2]/div/div/div/input').send_keys('123456aa')
sleep(2)
# 输入新密码
driver.find_element(By.XPATH, '/html/body/div[3]/div/div[2]/div[1]/div/form/div[3]/div/div/div/input').send_keys('gw09092434')
sleep(2)
# 输入确认密码
driver.find_element(By.XPATH, '/html/body/div[3]/div/div[2]/div[1]/div/form/div[4]/div/div/div/input').send_keys('gw09092434')
sleep(2)
# 点击确认按钮
an = driver.find_element(By.XPATH, '//*[@id="pwdSubmitBtn"]')
# 获取元素文本
print(f"元素文本：{an.text}")
# 获取元素尺寸
print(f"元素尺寸-宽度：{an.size['width']}, 高度：{an.size['height']}")
# 获取元素坐标
print(f"元素坐标-x：{an.location['x']}, y:{an.location['y']}")
an.click()
sleep(10)






